import React, { Component } from 'react'
import { Route, Redirect } from 'react-router-dom'
import { hasToken } from 'utils/storage'

export default class AuthRoute extends Component {
  render() {
    // console.log(this.props)
    const { component: Component, ...res } = this.props
    // console.log(res)
    return (
      <Route
        {...res}
        render={(props) => {
          //   console.log(hasToken())
          //   return <Component {...props} />
          // console.log(props.location.pathname)
          return hasToken() ? (
            <Component {...props} />
          ) : (
            <Redirect
              to={{
                pathname: '/login',
                state: {
                  from: props.location.pathname,
                },
              }}
            ></Redirect>
          )
        }}
      ></Route>
    )
  }
}
